﻿<%
Sa.Extends("checkAction")
'新闻管理类
Class newsAction
	'''构造
	Private Sub Class_Initialize()
		check.ForAjax()
	End Sub
	
	'''析构
	Private Sub Class_Terminate()
	End Sub
	
	'''添加新闻分类
	Public Sub cadd()
		Sa.Show()
	End Sub
	
	'''修改新闻分类
	Public Sub cedt()
		Sa.Dim("S_title")
		Sa.Dim("S_cid")
		Sa.Dim("S_pid")
		Sa.Dim("S_px")
		Sa.Dim("S_id")
		Dim t_rs : Set t_rs = Db.GRD("Nclass","id=" & IfHas(G("id"), P("id")))
		If Not t_rs.Eof Then
			S_title = t_rs("title")
			S_cid = t_rs("cid")
			S_pid = t_rs("pid")
			S_px = t_rs("px")
			S_id = t_rs("id")
		Else
			'Sa.ErrorE("未找到该记录")
			'Response.Write("{""statusCode"":300,""message"":""未找到该记录"",""navTabId"":"""",""rel"":"""",""callbackType"":"""",""forwardUrl"":"""",""confirmMsg"":""""}")
			'Response.End()
			check.WE300("未找到该记录!")
			'Core.WE("<script language='javascript'>alert('未找到该记录');history.go(-1);</script>")
		End If
		Db.C(t_rs)
	End Sub
	
	'''保存分类修改
	Public Sub csave()
		Sa.Use("Json")
		Dim t_res, t_t
		t_t = Lcase(IfHas(G("t"),P("t")))
		Select Case t_t
		Case "add"
			t_res = Db.AR("Nclass", Array("title:"&P("title"), "cid:"&P("cid"), "pid:"&P("pid"), "px:"&P("px"), "addtime:"&Now(), "editor:"&Session("adminid")))
		Case "edt"
			'Core.WE(Db.SUR("Nclass", "id="&P("id"), Array("title:"&P("title"), "cid:"&P("cid"), "pid:"&P("pid"), "px:"&P("px"), "addtime:"&Now(), "editor:"&Session("adminid"))))
			t_res = Db.UR("Nclass", "id="&P("id"), Array("title:"&P("title"), "cid:"&P("cid"), "pid:"&P("pid"), "px:"&P("px"), "addtime:"&Now(), "editor:"&Session("adminid")))
		Case "del"
			'批量删
			t_res = Db.DR("Nclass", "id:" & G("id"))
		Case Else
			'Sa.JumpUrl = "/?g=admin&m=news&a=clist"
			'Sa.ErrorE("不允许的操作类型!")
			'Response.Write("{""statusCode"":300,""message"":""不允许的操作类型!"",""navTabId"":"""",""rel"":"""",""callbackType"":"""",""forwardUrl"":"""",""confirmMsg"":""""}")
			'Response.End()
			check.WE300("不允许的操作类型!")
			'Core.WE("<script language='javascript'>alert('不允许的操作类型!');location.href='/?g=admin&m=news&a=clist';</script>")
		End Select
		If t_res Then
			'Sa.JumpUrl = "/?g=admin&m=news&a=clist"
			'Sa.Success("操作成功!")
			If t_t = "del" Then
				'Response.Write("{""statusCode"":200,""message"":""操作成功!"",""navTabId"":""news_clist"",""rel"":"""",""callbackType"":"""",""forwardUrl"":"""",""confirmMsg"":""""}")
				Call check.W200("操作成功!", "news_clist")
			Else
				'Response.Write("{""statusCode"":200,""message"":""操作成功!"",""navTabId"":"""",""rel"":"""",""callbackType"":""closeCurrent"",""forwardUrl"":"""",""confirmMsg"":""""}")
				Call check.W200("操作成功!", "")
			End If
			'Core.W("<script language='javascript'>alert('操作成功!');location.href='/?g=admin&m=news&a=clist';</script>")
		Else
			'Core.W("<script language='javascript'>alert('操作失败');history.go(-1);</script>")
			'Sa.Error("操作失败")
			'Response.Write("{""statusCode"":300,""message"":""操作失败"",""navTabId"":"""",""rel"":"""",""callbackType"":"""",""forwardUrl"":"""",""confirmMsg"":""""}")
			check.W300("操作失败!")
		End If
	End Sub
	
	'''新闻分类列表
	Public Sub clist()
		check.UsePager()
		Pager.PageNow = G(Pager.PageVar&":n:1")
		Sa.DimObject("crs")
		Set crs = Db.GR("Nclass","","id Asc")
		Pager.FormatRs(crs)
	End Sub
	
	'''添加新闻
	Public Sub add()
		Sa.Dim("S_csql")
		S_csql = "Select * From Nclass Order By px Asc"
		Sa.Show()
	End Sub
	
	'''修改新闻
	Public Sub edt()
		Sa.DimObject("rs")
		Sa.Dim("S_csql")
		S_csql = "Select * From Nclass Order By px Asc"
		Set rs = Db.GRD("News","id=" & IfHas(G("id"), P("id")))
		If rs.Eof Then
			'Core.WE("<script language='javascript'>alert('未找到该记录');history.go(-1);</script>")
			'Sa.ErrorE("未找到该记录")
			check.WE300("未找到该记录!")
		End If
	End Sub
	
	'''保存修改
	Public Sub save()
		Dim t_res
		Select Case Lcase(P("action"))
		Case "add"
			'Core.WE(P("content"))
			'Core.WE(Db.SAR("News", Array("title:"&P("title"), "content:"&P("content"), "editor:"&Session("adminid"), "addtime:"&Now(), "cid:"&P("cid"), "px:"&P("px"), "img:")))
			t_res = Db.AR("News", Array("title:"&P("title"), "content:"&P("content"), "editor:"&Session("adminid"), "addtime:"&Now(), "cid:"&P("cid"), "px:"&P("px"), "img:"))
		Case "edt"
			'Core.WE(Db.SUR("Nclass", "id="&P("id"), Array("title:"&P("title"), "cid:"&P("cid"), "pid:"&P("pid"), "px:"&P("px"), "addtime:"&Now(), "editor:"&Session("adminid"))))
			t_res = Db.UR("News", "id="&P("id"), Array("title:"&P("title"), "content:"&P("content"), "editor:"&Session("adminid"), "addtime:"&Now(), "cid:"&P("cid"), "px:"&P("px"), "img:"))
		Case "del"
			'批量删
			t_res = Db.DR("News", "id:" & P("id"))  
		Case Else
			'Sa.JumpUrl = "/?g=admin&m=news&a=list"
			'Sa.ErrorE("不允许的操作类型!")
			check.WE300("不允许的操作类型!")
			'Core.WE("<script language='javascript'>alert('不允许的操作类型!');location.href='/?g=admin&m=news&a=list';</script>")
		End Select
		If t_res Then
			'Core.W("<script language='javascript'>alert('操作成功!');location.href='/?g=admin&m=news&a=list';</script>")
			'Sa.JumpUrl = "/?g=admin&m=news&a=list"
			'Sa.Success("操作成功!")
			Call check.W200("操作成功!", "news_list")
		Else
			'Core.W("<script language='javascript'>alert('操作失败');history.go(-1);</script>")
			'Sa.Error("操作失败")
			check.W300("操作失败!")
		End If
	End Sub
	
	'''新闻列表
	Public Sub list()
		check.UsePager()
		Pager.PageNow = P(Pager.PageVar&":n:1")
		Sa.Dim("S_kwd") : S_kwd = P("kwd")
		Sa.Dim("S_adt") : S_adt = P("addtime")
		Dim t_cond : t_cond = ""
		If S_kwd <> "" Then
			t_cond = t_cond & "(title LIKE '%" & S_kwd & "%' OR content LIKE '%" & S_kwd & "%' OR editor LIKE '%" & S_kwd & "%')"
		End If
		If IsDate(S_adt) Then
			If t_cond <> "" Then
				t_cond = t_cond & " And "
			End If
			t_cond = t_cond & "DateDiff('d',addtime,'" & CDate(S_adt) & "')=0"
		End If
		Sa.DimObject("rs")
		Set rs = Db.GR("News",t_cond,"id Asc")
		'Response.Write(Db.SGR("Nclass","","id Asc"))
		'Response.End
		Pager.FormatRs(rs)
	End Sub
	
End Class
%>